/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package utility;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Jeppe
 */
public class FileHandler {

    private static final boolean DEBUGMODE = false;

    

    public static void writeFile(String title, String[] lineArr) throws IOException {
        FileWriter fw = new FileWriter(title);
        PrintWriter pw = new PrintWriter(fw);

        for (int i = 0; i < lineArr.length; i++) {
            pw.println(lineArr[i]);
            if(DEBUGMODE){
                System.out.println(lineArr[i]);
            }
        }

        pw.close();
    }

    public static ArrayList<String> readFile(String url) throws FileNotFoundException {
        Scanner fileScanner = new Scanner(new File(url));
        ArrayList<String> stringList = new ArrayList<>();

        while(fileScanner.hasNext()){
            stringList.add(fileScanner.nextLine());
            if (DEBUGMODE) {
                System.out.println(stringList.get(stringList.size()-1));                
            }
        }
        fileScanner.close();

        return stringList;
    }
    
    

}
